

package com.hd.assistant.web.home.module.screen.json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.alibaba.fastjson.JSONObject;
import com.hd.assistant.dal.dataobject.User;
import com.hd.assistant.web.common.base.ordermining.BaseTaobaoOrderModule;
/**
 *
 * @author Hangding
 */
public class UserUpdate extends BaseTaobaoOrderModule{
    private final static Logger log = LoggerFactory.getLogger(UserUpdate.class);
    @Autowired
    private HttpServletRequest request;

    @Autowired
    private HttpServletResponse response;

    @Autowired
    private HttpSession session;
    
    
   
    public void execute(
    		@Param("creditCardRate") Double creditCardRate,
    		@Param("tmallRate") Double tmallRate,
    		@Param("email") String email,
    		@Param("phone") String phone,
    		Context context, Navigator nav) {
    	try{
    		User u = checkPermision(User.Type_TAOBAO_ORDER, session, context, nav);
    		if(u == null)
    			return;
    		User update = new User();
    		update.setId(u.getId());
    		boolean needUpdate = false;
    		if(creditCardRate != null){
    			update.setCreditCardRate(creditCardRate);
    			u.setCreditCardRate(creditCardRate);
    			needUpdate = true;
    		}
    		if(tmallRate != null){
    			update.setTmallRate(tmallRate);
    			u.setTmallRate(tmallRate);
    			needUpdate = true;
    		}
    		if(email != null){
    			update.setEmail(email);
    			u.setEmail(email);
    			needUpdate = true;
    		}
    		if(phone != null){
    			update.setPhone(phone);
    			u.setPhone(phone);
    			needUpdate = true;
    		}
    		
    		if(needUpdate){
    			this.assistantManager.updateUser(update);
    			session.setAttribute("user", u);
    			itemCostCacheManager.updateOrderMiningUser(u.getUserId());
    			JSONObject object = new JSONObject();
	    		object.put("success", true);
	    		context.put("result", object.toJSONString());
    		}
    	}catch(Exception e){
    		log.error("error Itemcosts ",e);
    	}
	    	
    }
	
}
